/*
 * Copyright (C) 2015  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


/**
 * @file
 * @brief Generic functions to compute statistics of positions.
 */


#ifndef PLANET_WARS_2D_RT_CORE_STATISTICS_POSITION_2D_GENERIC_H
#define PLANET_WARS_2D_RT_CORE_STATISTICS_POSITION_2D_GENERIC_H


#include "PlanetWars2dRT-core/utils/bool.h"


#define SUM_TABLE_POSITION_2D(tab, tab_size, result)	\
  do							\
    {							\
      result.x = 0;					\
      result.y = 0;					\
      for(size_t _i=0; _i < tab_size; ++_i)		\
	{						\
	  result.x += tab[_i].x;			\
	  result.y += tab[_i].y;			\
	}						\
    }							\
  while(false);

#define AVERAGE_TABLE_POSITION_2D(tab, tab_size, result)	\
  do								\
    {								\
      SUM_TABLE_POSITION_2D(tab, tab_size, result);		\
      result.x /= tab_size;					\
      result.y /= tab_size;					\
    }								\
  while(false);


#endif
